<?php
/**
 * Created by PhpStorm.
 * User: yuliang
 * Date: 2017/6/15
 * Time: 下午4:52
 */

namespace app\admin\controller;

use app\common\controller\Api;
use think\Db;
use think\Request;

class Login extends Api {

    public function login(){
        $account = input('post.account');
        $password = md5(md5(input('post.password')).config('salt_key'));
        $model = Db::name('admin');
        $user = $model->field('id,account,name')->where(['account'=>$account,'password'=>$password,'status'=>1])->find();
        if($user){
            $data['login_time'] = date('Y-m-d H:i:s',time());
            $data['login_count'] = ['exp','login_count + 1'];
            $data['login_ip'] = request()->ip();
            $update = $model->where('account',$account)->update($data);
            $user['token'] = $this->getAuthToken($user['id']);
            return api_return('操作成功！',$user);
        }else{
            return api_error('50001','账号或密码错误！');
        }
    }
}